home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip1292.zip / ATR2ANSI.C < prev    next >
Text File  |  1992-12-26  |  2KB  |  81 lines

  1. /*
  2. **  Form a command string for ANSI.SYS to set a given video attribute
  3. **
  4. **  Public domain demo by Bob Stout
  5. */
  6.  
  7. /* video attributes */
  8.  
  9. #define BLINKING 0x87
  10. #define REVERSE 0x70
  11. #define REVBLINK 0xf0
  12. #define NORMAL 0x07
  13. #define HIGHLITE 0x0f
  14. #define HIGHBLINK 0x8f
  15. #define BLINKBIT 0x80   /* OR in to cause blink */
  16. #define HILTBIT 0x08    /* OR in to cause highlight */
  17.  
  18. /*
  19. ** colors -- Use as is for foreground colors
  20. **           For background, shift left by 4 and OR with
  21. **           foreground and possible video attributes
  22. */
  23.  
  24. #define BLACK 0
  25. #define BLUE 1
  26. #define GREEN 2
  27. #define CYAN 3
  28. #define RED 4
  29. #define MAGENTA 5
  30. #define BROWN 6
  31. #define WHITE 7
  32. #define GRAY 8
  33. #define LTBLUE 9
  34. #define LTGREEN 10
  35. #define LTCYAN 11
  36. #define LTRED 12
  37. #define LTMAGENTA 13
  38. #define YELLOW 14
  39. #define HIWHITE 15    /* hi-intensity white */
  40.  
  41. #define BG_(a) (((a) & 0x7f) << 4)
  42.  
  43. /*
  44. **  Example:
  45. **   Video attribute of yellow text on blue background = BG_(BLUE)+YELLOW
  46. */
  47.  
  48. char *make_ansi(int vatr)
  49. {
  50.         void add_str(char *, char *);
  51.         static char string[40];
  52.  
  53.         static char *fore[8] = {"30","34","32","36","31","35","33","37"};
  54.         static char *back[8] = {"40","44","42","46","41","45","43","47"};
  55.  
  56.         strcpy(string, "\033[");
  57.         if (vatr == 0x07)
  58.                 strcat(string, "0");
  59.         else
  60.         {
  61.                 if (vatr & 0x80)
  62.                         add_str(string, "5");
  63.                 if (vatr & 0x08)
  64.                         add_str(string, "1");
  65.                 add_str(string, fore[vatr & 0x07]);
  66.                 add_str(string, back[(vatr & 0x70) >> 4]);
  67.         }
  68.         strcat(string, "m");
  69.         return string;
  70. }
  71.  
  72. void add_str(char *string1, char *string2)
  73. {
  74.         char last_char;
  75.  
  76.         last_char = string1[strlen(string1) - 1];
  77.         if (last_char != '[')
  78.                 strcat(string1, ";");
  79.         strcat(string1, string2);
  80. }
  81.